﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HRM.Models;

namespace HRM.Controllers.DangKy
{
    public class DangKy_QLSuPhamController : Controller
    {
        private HRMTTNS41Context db = new HRMTTNS41Context();

        //
        // GET: /DangKy_QLSuPham/

        public ActionResult Index()
        {
            return View(db.dk_QLSuPham.ToList());
        }

        //
        // GET: /DangKy_QLSuPham/Details/5

        public ActionResult Details(int id = 0)
        {
            dk_QLSuPham dk_qlsupham = db.dk_QLSuPham.Find(id);
            if (dk_qlsupham == null)
            {
                return HttpNotFound();
            }
            return View(dk_qlsupham);
        }

        //
        // GET: /DangKy_QLSuPham/Create

        public ActionResult Create(string ids = "")
        {
            ids=@Session["storeid"].ToString();
            var count = db.dk_QLSuPham.Count(u => u.MaDDKy ==ids );
            if (count == 0)
            {
                return View();
                //add user
            }
            else
            {
                return View("DotDKError2");
               
                //alert user saying user exists
            }
            
        }

        //
        // POST: /DangKy_QLSuPham/Create

        [HttpPost]
        public ActionResult Create(dk_QLSuPham dk_qlsupham)
        {
           
            if (ModelState.IsValid)
            {
                db.dk_QLSuPham.Add(dk_qlsupham);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(dk_qlsupham);
        }

        //
        // GET: /DangKy_QLSuPham/Edit/5

        public ActionResult Edit(int id = 0,string ids= "")
        {

                ids = @Session["storeid"].ToString();

            dk_QLSuPham dk_qlsupham = db.dk_QLSuPham.FirstOrDefault(i=>i.MaDDKy== ids );
            if (dk_qlsupham == null)
            {
                return View("DotDKError");
            }
            return View(dk_qlsupham);
        }

        //
        // POST: /DangKy_QLSuPham/Edit/5

        [HttpPost]
        public ActionResult Edit(dk_QLSuPham dk_qlsupham)
        {
            if (ModelState.IsValid)
            {
                db.Entry(dk_qlsupham).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(dk_qlsupham);
        }

        //
        // GET: /DangKy_QLSuPham/Delete/5

        public ActionResult Delete(int id = 0)
        {
            dk_QLSuPham dk_qlsupham = db.dk_QLSuPham.Find(id);
            if (dk_qlsupham == null)
            {
                return HttpNotFound();
            }
            return View(dk_qlsupham);
        }

        //
        // POST: /DangKy_QLSuPham/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            dk_QLSuPham dk_qlsupham = db.dk_QLSuPham.Find(id);
            db.dk_QLSuPham.Remove(dk_qlsupham);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}